package com.telit.firecommand.strategy.context;

import com.telit.firecommand.strategy.FirePersonStrategyInterface;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


@Component
public class FirePersonStrategyContext {


    private final Map<String, FirePersonStrategyInterface> personMap = new ConcurrentHashMap<>();

    @Autowired
    public FirePersonStrategyContext(Map<String, FirePersonStrategyInterface> personMap) {
        this.personMap.clear();
        personMap.forEach(this.personMap::put);
    }

    public void excelImportPerson(String beanName, MultipartFile file, Long id) throws Exception {
        if (StringUtils.isNotBlank(beanName)) {
            personMap.get(beanName).excelImportPerson(file, id);
        }
    }

}
